//------------------------------------------------------------------------------
// Copyright (c) 2008 www.dnaide.com
// Licensed under the MIT (MIT-LICENSE.txt)
//------------------------------------------------------------------------------
using System;
using System.Collections.Specialized;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Configuration;

using DNAide.Core;

namespace DNAide.Configuration
{

	internal static partial class ConfigAide
	{
		
		/// <summary>
		/// </summary>
		/// <param name="config"></param>
		internal static void CheckForUnrecognizedAttributes(NameValueCollection config)
		{
			if (config == null)
			{
				throw new ArgumentNullException("config");
			}

			if (config.Count > 0)
			{
				string attribUnrecognized = config.GetKey(0);
				if (!String.IsNullOrEmpty(attribUnrecognized))
					throw new ConfigurationErrorsException(
						StringAide.FormatInvariant(Resources.ConfigAide.UnexpectedProviderAttribute, attribUnrecognized));
			}
		}


		/// <summary>
		/// </summary>
		/// <param name="config"></param>
		/// <param name="attributeName"></param>
		/// <param name="returnValue"></param>
		internal static void GetAndRemoveStringAttribute(NameValueCollection config, string attributeName, ref string returnValue)
		{
			if (config == null)
			{
				throw new ArgumentNullException("config");
			}

			returnValue = config.Get(attributeName);
			config.Remove(attributeName);
		}


		/// <summary></summary>
		internal class ReadOnlyNameValueCollection : NameValueCollection
		{
			/// <summary></summary>
			public ReadOnlyNameValueCollection()
			{
				IsReadOnly = true;
			}

			/// <summary></summary>
			public void SetReadOnly(bool isReadonly)
			{
				IsReadOnly = isReadonly;
			}
		}

	}
}
